package com.yb.framework.core.domain;

import com.yb.framework.core.constant.HttpStatusCode;

import lombok.Data;

@Data
public class AjaxObject {
	
	private int statusCode;
	private String message;
	
	public AjaxObject() {
		super();
	}
	public AjaxObject(int statusCode, String message) {
		super();
		this.statusCode = statusCode;
		this.message = message;
	}
	
	public static AjaxObject newOk() {
		return new AjaxObject(HttpStatusCode.OK, "恭喜你，操作成功！");
	}
	public static AjaxObject newOk(String message) {
		return new AjaxObject(HttpStatusCode.OK, message);
	}
	public static AjaxObject newOk(int statusCode, String message) {
		return new AjaxObject(statusCode, message);
	}
	
	public static AjaxObject newError() {
		return new AjaxObject(HttpStatusCode.ERROR, "操作失败，请重试！");
	}
	public static AjaxObject newError(String message) {
		return new AjaxObject(HttpStatusCode.ERROR, message);
	}
	public static AjaxObject newError(int statusCode, String message) {
		return new AjaxObject(statusCode, message);
	}
	
	@Override
	public String toString() {
		StringBuffer buffer = new StringBuffer();
		buffer.append("{").
				append("\"statusCode\":" + statusCode + ",").
				append("\"message\":\"" + message + "\"").
				append("}");
		return buffer.toString();
	}
}
